package com.qidian.by.goods.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.Properties;

/**
 * @Author: CoolPro
 * @Description: 订阅模式节点
 * @Time: 2024-05-17 17:14
 **/

@Configuration
public class FanoutRabbitConfig {
    @Resource
    private Properties fanoutExchangeProperty;

//    提交一个订阅交换机
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(fanoutExchangeProperty.getProperty("fanout-exchange"), true, false);
    }
    @Bean
    public Queue itemQuery(){
        //参数1：队列名称
        //参数2：是否持久化
        return new Queue(fanoutExchangeProperty.getProperty("item-queue"), true);
    }
    @Bean
    public Queue searchQueue(){
        //参数1：队列名称
        //参数2：是否持久化
        return new Queue(fanoutExchangeProperty.getProperty("search-queue"), true);
    }

    @Bean
    public Binding bindingItemQueue() {
        //给路由绑定消息
        return BindingBuilder.bind(itemQuery()).to(fanoutExchange());
    }

    @Bean
    public Binding bindingSearchQueue() {
        //给路由绑定消息
        return BindingBuilder.bind(searchQueue()).to(fanoutExchange());
    }

}
